package com.haohe.wx.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.haohe.wx.util.PropertiesReadUtil;
import com.haohe.wx.util.SpringUtil;

/**
 * @Title 初始化微信参数
 * @Description TODO
 * @author liming.zhao@haohedata.com
 */
public class SpringListener implements ServletContextListener {
	private static Logger logger = Logger.getLogger(SpringListener.class);
	
	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {

	}

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		ServletContext context = servletContextEvent.getServletContext();
		try {
			ApplicationContext ctx = WebApplicationContextUtils
					.getRequiredWebApplicationContext(context);
			SpringUtil.setContext(ctx);
			PropertiesReadUtil.INSTANCE.load("/wxConfig.properties");
		} catch (Throwable t) {
			logger.error(t.getMessage());
		}
	}

}